package effective.java.chapter2.item2.hierarchicalbuilder;

/**
 * @Author ZhangGJ
 * @Date 2021/01/27 07:27
 */
public class Calzone extends Pizza {

    private final boolean sauceInside;


    public static class Builder extends Pizza.Builder<Builder> {
        private boolean sauceInside = false; // Default

        public Builder sauceInside() {
            sauceInside = true;
            return this;
        }

        @Override
        public Calzone build() {
            return new Calzone(this);
        }

        @Override
        protected Builder self() {
            return this;
        }
    }

    private Calzone(Builder builder) {
        super(builder);
        sauceInside = builder.sauceInside;
    }

    @Override
    public String toString() {
        return String.format("Calzone with %s and sauce on the %s", toppings,
                sauceInside ? "inside" : "outside");
    }
}
